@extends('simple-pc.views.layout')
@section('content')
    <link rel="stylesheet" href="/themes/simple-pc/static/css/list.css?v=1.1">
    <div class="banner" style="background-image: url('{{$category_info['thumb']}}')">
    </div>
    <div class="case-cat">
        @php $category_list = cms_category_list(['order'=>'display_order desc,id desc','where'=>'type=0']) @endphp
        @foreach ($category_list as $item)
            <a href="/article/list?cid={{$item['id']}}" class="case-cat-item @if ($item['id']==$cid) case-cat-active @endif">
                <span class="case-cat-item-text">{{$item['name']}}</span>
            </a>
        @endforeach
    </div>
    <div class="case-con clearfix">
        <div class="case-list-con clearfix">
            @foreach ($list as $item)
                <div class="case-list-item">
                    <a href="/article/detail?id={{$item['id']}}">
                        <div class="case-list-item-img img-con">
                            <img src="{{$item['thumb']}}">
                        </div>
                        <div class="case-list-item-desc">
                            {{$item['description']}}
                        </div>
                    </a>
                </div>
            @endforeach
        </div>
        @php
            $totalItem = $list->total();
            $pageSize = $list->perPage();
            $currentPage = $list->currentPage();
            $totalPage = ceil($totalItem/$list->perPage());
        @endphp
        @if ($totalItem>=10)
            <div class="page-ctrl">
                <sapn class="total-item">共{{$totalItem}}条</sapn>
                <sapn class="page-size">10条/页</sapn>
                @if ($currentPage==1)
                    <a class="prev-page disabled btn-dis"> < </a>
                @else
                    <a href="/article/list?cid={{$category_info['id']}}&page={{$currentPage-1}}" class="prev-page"> < </a>
                @endif
                @for($i=0;$i<$totalPage-1;$i++)
                    @if($totalPage>8&&$currentPage>6&&$i<$currentPage-3)
                        @if($i<2)
                            <a href="/article/list?cid={{$category_info['id']}}&page={{$i+1}}" class="page-num">{{$i+1}}</a>
                        @elseif($i==2)
                            <span class="page-dot">...</span>
                        @endif
                    @elseif($totalPage>8&&$currentPage<$totalPage-3&&$i>$currentPage+1)
                        @if($currentPage>6&&$i==$currentPage+2)
                            <span class="page-dot">...</span>
                        @elseif($currentPage<7)
                            @if($i<8)
                                <a href="/article/list?cid={{$category_info['id']}}&page={{$i+1}}" class="page-num">{{$i+1}}</a>
                            @elseif($i==8)
                                <span class="page-dot">...</span>

                            @endif

                        @endif
                    @else
                        @if($i==$currentPage-1)
                            <a href="/article/list?cid={{$category_info['id']}}&page={{$currentPage}}" class="page-num current-page">{{$i+1}}</a>
                        @else
                            <a href="/article/list?cid={{$category_info['id']}}&page={{$i+1}}" class="page-num">{{$i+1}}</a>
                        @endif
                    @endif

                @endfor
                @if($currentPage==$totalPage)
                    <a href="/article/list?cid={{$category_info['id']}}&page={{$i+1}}" class="page-num current-page">{{$i+1}}</a>
                @else
                    <a href="/article/list?cid={{$category_info['id']}}&page={{$i+1}}" class="page-num">{{$i+1}}</a>

                @endif
                @if($currentPage==$totalPage)
                    <a class="next-page disabled btn-dis"> > </a>
                @else
                    <a href="/article/list?cid={{$category_info['id']}}&page={{$currentPage+1}}" class="next-page"> > </a>
                @endif
                <a id="js_to_page" class="page-total">前往</a>
                <input id="js_page-num" class="input-page-num" type="text" value="">
                <span class="page_text">页</span>
            </div>
        @endif
    </div>


    <script>
        $(function(){
            var currentPage = {{$currentPage}};
            $('#js_to_page').click(function () {
                var pageNUm = parseInt($('#js_page-num').val());
                var  totalPage = {{$totalPage}};
                if(pageNUm<=totalPage ||pageNUm>0){
                    if(pageNUm!=currentPage){
                        window.location.href='/article/list?cid={{$category_info['id']}}&page='+pageNUm;
                    }
                }
            });
        })
    </script>
@endsection
